
import { Component, Watch } from 'vue-property-decorator';
import { VueLifeCycleProcessing,AppControlBase } from 'ibiz-vue';
import { AppDefaultForm } from 'ibiz-vue/src/components/control/app-default-form/app-default-form';
import { Util } from 'ibiz-core';


/**
 * 只读表单插件类
 *
 * @export
 * @class ReadonlyForm
 * @class ReadonlyForm
 * @extends {Vue}
 */
@Component({})
@VueLifeCycleProcessing()
export class ReadonlyForm extends AppDefaultForm {


/**
     * 绘制表单项
     *
     * @returns
     * @memberof AppFormBase
     */
    public renderFormItem(modelJson: any, index: number): any {
        const { compositeItem, contentWidth, contentHeight } = modelJson;
        let editor = modelJson.getPSEditor();
        const refFormItem: any = [];
        const style = {
            width: contentWidth ? `${contentWidth}px` : false,
            height: contentHeight ? `${contentHeight}px` : false,
        };
        if (compositeItem) {
            let formItems = (modelJson as any).getPSDEFormItems();
            formItems?.forEach((formItem: any) => {
                refFormItem.push(formItem?.id);
            });
        }
        const isDebounce: boolean = !Object.is(this.controlInstance.controlType,"FORM");
        return (
            <app-default-form-item
                detailsInstance={modelJson}
                index={index}
                data={this.data}
                modelService={this.modelService}
                rules={this.rules[modelJson.name]}
                runtimeModel={this.detailsModel[modelJson.name]}
                context={Util.deepCopy(this.context)}
                viewparams={Util.deepCopy(this.viewparams)}
                contextState={this.formState}
                service={this.service}
                ignorefieldvaluechange={this.ignorefieldvaluechange}
                on-formItemValueChange={(value: any) => {
                    this.onFormItemValueChange(value);
                }}
                controlInstance={this.controlInstance}
            >
                {editor && (
                    <app-default-editor
                        editorInstance={editor}
                        ref={editor.name}
                        containerCtrl={this.controlInstance}
                        parentItem={modelJson}
                        value={this.data[editor?.name]}
                        contextData={this.data}
                        valueFormat={modelJson.valueFormat}
                        context={Util.deepCopy(this.context)}
                        viewparams={Util.deepCopy(this.viewparams)}
                        contextState={this.formState}
                        service={this.service}
                        disabled={true}
                        isDebounce={isDebounce}
                        ignorefieldvaluechange={this.ignorefieldvaluechange}
                        on-change={(value: any) => {
                            this.onFormItemValueChange(value);
                        }}
                    />
                )}
            </app-default-form-item>
        );
    }
	

}


